import json
from typing import Dict, Any

class Config:
    """Base configuration class for PocketFlow."""
    
    def __init__(self, config_dict: Dict[str, Any] = None):
        """Initialize configuration.
        
        Args:
            config_dict: Dictionary containing configuration parameters.
        """
        if config_dict is not None:
            self.update(config_dict)
    
    def update(self, config_dict: Dict[str, Any]):
        """Update configuration with new parameters.
        
        Args:
            config_dict: Dictionary containing new configuration parameters.
        """
        for key, value in config_dict.items():
            setattr(self, key, value)
    
    @classmethod
    def from_json(cls, file_path: str):
        """Load configuration from JSON file.
        
        Args:
            file_path: Path to JSON configuration file.
            
        Returns:
            Config instance loaded from JSON file.
        """
        with open(file_path, 'r') as f:
            config_dict = json.load(f)
        return cls(config_dict)
    
    def to_dict(self) -> Dict[str, Any]:
        """Convert configuration to dictionary.
        
        Returns:
            Dictionary containing all configuration parameters.
        """
        return {k: v for k, v in self.__dict__.items() 
                if not k.startswith('_')}
    
    def save(self, file_path: str):
        """Save configuration to JSON file.
        
        Args:
            file_path: Path to save JSON configuration file.
        """
        with open(file_path, 'w') as f:
            json.dump(self.to_dict(), f, indent=4)